#include <stdio.h>



int main(){
	
	
	int n,i,j,a,b;
	char tem[30]={0};
	scanf("%d",&n);
	
	struct student{

    char name[21];
	int sno;
	double chinese;
	double english;
	double math;
	double sum;

	};
	

	struct student balls[n];
	
	for(i=0;i<n;i++){
		scanf("%s %d %lf %lf %lf",balls[i].name,&balls[i].sno,&balls[i].chinese,&balls[i].english,&balls[i].math);
		balls[i].sum=balls[i].chinese+balls[i].english+balls[i].math;
	}
	

	
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++)
			if(balls[j].sum>balls[i].sum){
			a=balls[i].sum;
			balls[i].sum=balls[j].sum;
			balls[j].sum=a;		
			strcpy(tem,balls[i].name);
            strcpy(balls[i].name,balls[j].name);
            strcpy(balls[j].name,tem);
			b=balls[i].sno;
			balls[i].sno=balls[j].sno;
			balls[j].sno=b;	
			}
			if(balls[j].sum==balls[i].sum){
				if(strcmp(balls[i].name,balls[j].name)>0)
            	{
                  strcpy(tem,balls[i].name);
                  strcpy(balls[i].name,balls[j].name);
                  strcpy(balls[j].name,tem);
                  a=balls[i].sum;
				  balls[i].sum=balls[j].sum;
				  balls[j].sum=a;
				  b=balls[i].sno;
			      balls[i].sno=balls[j].sno;
			      balls[j].sno=b;
           		}
			}
	}
		
	
	for(i=0;i<n;i++)
		printf("[name:%s,sum:%.0lf,sno:%d]\n",balls[i].name,balls[i].sum,balls[i].sno);
	

	
	return 0;
}





 
